﻿using System;
using System.Collections.Generic;
using Common.Model;
using GxTsSharp.Models;

namespace StockIndex.service
{
    //简单的指标service
    public class SimpleIndicatorService
    {
        public static void UpdateSimpleIndicator()
        {
            var indicatorDic = MemoryDataDB.TopicSimpleIndicatorDic;
            indicatorDic.Clear();
            foreach (var topicStock in MemoryDataDB.TopicStocks)
            {
                SimpleIndicatorModel simpleIndicatorModel = new SimpleIndicatorModel();
                String topicName = topicStock.Key;
                HashSet<String> stocks = topicStock.Value;
                indicatorDic.AddOrUpdate(topicName, simpleIndicatorModel,(k,v)=>simpleIndicatorModel);

                foreach (var stock in stocks)
                {
                    //根据涨跌幅计算一些简单指标

                    decimal zdf = MemoryDataDB.GetStockZdf(stock);
                    //上涨，下跌股票数
                    if (zdf > 0)
                    {
                        simpleIndicatorModel.UpCount++;
                    }
                    else
                    {
                        simpleIndicatorModel.DownCount++;
                    }

                    //涨停跌停股票数
                    if (zdf >= 10)
                    {
                        simpleIndicatorModel.SurgedLimitCount++;
                    }
                    else if (zdf <= -10)
                    {
                        simpleIndicatorModel.DeclineLimitCount++;
                    }
                }
                
            }
        }
    }
}